<?php
#
# VERSION
#
define('PLUGIN_VERSION', '1.0');
define('PLUGIN_CREDITS', 'ported from Wordpress');
define('PLUGIN_AUTHOR', 'Petko D. (pdp) Petkov');
define('PLUGIN_AUTHOR_HOMEPAGE', 'http://www.gnucitizen.org/about/pdp');

#
# HELPERS
#
function build_unique_plugin_id($tag, $function, $priority=10) {
	return $function;
}

#
# FILTERS
#
function add_filter($tag, $function, $priority=10) {
	global $TEMP;

	$id = build_unique_plugin_id($tag, $function, $priority);

	$TEMP['filters'][$tag][$priority][$id] = array('function' => $function);
}

function apply_filters($tag, $input='') {
	global $TEMP;

	if (!isset($TEMP['filters'][$tag])) {
		return $input;
	}

	reset($TEMP['filters'][$tag]);

	do {
		foreach ((array)current($TEMP['filters'][$tag]) as $the_) {
			if (!is_null($the_['function'])) {
				$input = call_user_func($the_['function'], $input);
			}
		}
	} while (next($TEMP['filters'][$tag]) !== false);

	return $input;
}

function remove_filter($tag, $function, $priority=10) {
	global $TEMP;

	$id = build_unique_plugin_id($tag, $function, $priority);

	unset($TEMP['filters'][$tag][$priority][$function]);
}

#
# ACTIONS
#
function add_action($tag, $function, $priority=10) {
	global $TEMP;

	$id = build_unique_plugin_id($tag, $function, $priority);

	$TEMP['actions'][$tag][$priority][$id] = array('function' => $function);
}

function apply_actions($tag, $input='') {
	global $TEMP;

	if (!isset($TEMP['actions'][$tag])) {
		return $input;
	}

	reset($TEMP['actions'][$tag]);

	do {
		foreach ((array)current($TEMP['actions'][$tag]) as $the_) {
			if (!is_null($the_['function'])) {
				call_user_func($the_['function'], $input);
			}
		}
	} while (next($TEMP['actions'][$tag]) !== false);
}

function remove_action($tag, $function, $priority=10) {
	global $TEMP;

	$id = build_unique_plugin_id($tag, $function, $priority);

	unset($TEMP['actions'][$tag][$priority][$function]);
}
